package ru.st.selenium.pages;


import static org.openqa.selenium.support.ui.ExpectedConditions.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {

        public InternalPage(PageManager pages) {
                super(pages);
        }
       
  public InternalPage ensurePageLoaded() {
    super.ensurePageLoaded();
    wait.until(presenceOfElementLocated(By.cssSelector("nav")));
    return this;
  }
 

  @FindBy(xpath = "//a[contains(@href, '/php4dvd/?logout')]")
  private WebElement logoutLink;
 
  @FindBy(css = "img[alt=\"Add movie\"]")
  private WebElement addFilmLink;
 
  @FindBy(css = "div.nocover")
  private WebElement filmOpenLink;
 
  @FindBy(css = "img[alt=\"Remove\"]")
  private WebElement filmDeleteLink;
 
  @FindBy(id="q")
  private WebElement filmSearchLink;
 
  public AddFilmPage clickAddFilmPage() {
    addFilmLink.click();
    return pages.addFilmPage;
  }

 
  public LoginPage clickLogoutLink() {
    logoutLink.click();
    wait.until(alertIsPresent()).accept();
    return pages.loginPage;
  }
 
   public InternalPage clickFilmSearch(String s){
            try   {wait.until(presenceOfElementLocated(By.cssSelector("div.nocover")));
                  } catch (Exception e) {}
                  filmSearchLink.clear();
          filmSearchLink.sendKeys(s+Keys.RETURN);
          return this;
  }
  public InternalPage clickfilmOpen() {
            filmOpenLink.click();
  return this;
  }
  public InternalPage clickfilmDelete() {
            filmDeleteLink.click();
            wait.until(alertIsPresent()).accept();
  return this;
  }

  public InternalPage clickfilmNotDelete() {
            filmDeleteLink.click();
            wait.until(alertIsPresent()).dismiss();
  return this;
  }
  public InternalPage waitload(Integer nTime){
          try { Thread.sleep(nTime);
                } catch (InterruptedException e) {                      
                }  
          return this;
  }
 }

